﻿@{
    ViewBag.Title = "材料设置界面";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var Type=request('Type')
    $(function () {      
        GetGrid();
    });
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable2');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_MaterialSetting/GetMaterialJson?Type="+Type,           
            datatype: "json",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "Code", name: "Code", index: "Code", width: 80, align: "left",hidden:true },
                { label: "名称", name: "Name", index: "Name", width: 120, align: "left" },
                { label: "标准说明", name: "Description", index: "Description", width: 200, align: "left" },
                { label: "排序", name: "Sort", index: "Sort", width: 80, align: "left" },
                {
                    label: "是否提交", name: "IsSubmit", index: "IsRequired", width: 80, align: "left",
                    formatter: function (cellvalue, options, rowObject)
                    {
                        if (cellvalue == 1) {
                            return "是";
                        }
                        else
                        {
                            return "否";
                        }
                    }
                },
                 {
                     label: "是否上传", name: "IsUpload", index: "IsUpload", width: 80, align: "left",
                     formatter: function (cellvalue, options, rowObject) {
                         if (cellvalue == 1) {
                             return "是";
                         }
                         else {
                             return "否";
                         }
                     }
                 },
                {
                    label: "是否有效", name: "EnabledMark", index: "EnabledMark", width: 80, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return "是";
                        }
                        else {
                            return "否";
                        }
                    }
                },
                { label: "示例图片", name: "DemoImage", index: "Area", width: 80, align: "DemoImage" },
                { label: "创建人", name: "CreateUserName", index: "CreateUserName", width: 80, align: "left" },
                { label: "创建时间", name: "CreateDate", index: "CreateDate", width: 80, align: "left" }   
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["State"] = _state;
            queryJson["PSAllName"] = _psallname;
            queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
            $gridTable.jqGrid('setGridParam', {
                url: "../../PropertyManage/CS_Decorate/GetPageListJson",
                postData: { queryJson: JSON.stringify(queryJson) },
                page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //新增
    function btn_AddMaterial() {
        dialogOpen({
            id: "AddMaterial",
            title: '添加',
            url: '/PropertyManage/CS_MaterialSetting/AddMaterial?type=' + Type,
            width: "550px",
            height: "550px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
                document.location.reload();//当前页面                  
            }
        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable2").jqGridRowValue("Code");        
        if (checkedRow(keyValue)) {
                dialogOpen({
                    id: "AddMaterial",
                    title: '编辑',
                    url: '/PropertyManage/CS_MaterialSetting/AddMaterial?keyValue=' + keyValue + "&type=" + Type,
                    width: "700px",
                    height: "430px",
                    //btn: null
                    callBack: function (iframeId) {
                        top.frames[iframeId].AcceptClick();
                    }
                });
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable2").jqGridRowValue("Code");
        if (keyValue) {           
            dialogConfirm('注：您确定要移除吗？该操作将无法恢复？', function (r) {
                if (r) {
                    $.ajax({
                        type: "POST",
                        url: "/PropertyManage/CS_MaterialSetting/RemoveForm",
                        async: false,
                        data: { keyValue: keyValue },
                        success: function () {                            
                            document.location.reload();//当前页面                             
                        }

                    })
                    dialogMsg("操作成功。", 1);                
                }
            });
        } else {
            dialogMsg('请选择需要删除的业务！', 0);
        }
    }
  
</script>

    <div class="titlePanel">
        <div class="title-search" >
            <div class="btn-group">
                <a id="lr-addMaterial" class="btn btn-default" onclick="btn_AddMaterial()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                <a id="lr-editMaterial" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                <a id="lr-deleteMaterial" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
            </div>
            @*<script>$('.btn-group').authorizeButton()</script>*@
        </div>
   </div>
    <div class="gridPanel">
        <table id="gridTable2"></table>
    </div>
